package com.puntodonna.fogliocassa.client.widget;

import java.util.Date;

import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.datepicker.client.DateBox;

public class FoglioCassaInputDialogBox extends DialogBox {

	private static FoglioCassaInputDialogBoxUiBinder uiBinder = GWT.create(FoglioCassaInputDialogBoxUiBinder.class);

	interface FoglioCassaInputDialogBoxUiBinder extends UiBinder<Widget, FoglioCassaInputDialogBox> {
	}

	@UiField
	protected DateBox dateBox;
	@UiField
	protected TextBox nomeTextBox;
	@UiField
	protected Button okBtn;
	@UiField
	protected Button cancelBtn;

	public FoglioCassaInputDialogBox(Date date) {
		this(date, DateTimeFormat.getFormat("dd/MM/yyyy HH:mm:ss"));
	}

	public FoglioCassaInputDialogBox(Date date, DateTimeFormat format) {
		setWidget(uiBinder.createAndBindUi(this));
		getDateBox().setValue(date, true);
		getDateBox().setFormat(new DateBox.DefaultFormat(format));
		setNameByDate(date);
	}

	public FoglioCassaInputDialogBox() {
		this(new Date(), DateTimeFormat.getFormat("dd/MM/yyyy HH:mm:ss"));
	}

	public TextBox getNomeTextBox() {
		return nomeTextBox;
	}

	public DateBox getDateBox() {
		return dateBox;
	}

	public Button getOkBtn() {
		return okBtn;
	}

	public Button getCancelBtn() {
		return cancelBtn;
	}

	public void setNameByDate(Date date) {
		getNomeTextBox().setText(DateTimeFormat.getFormat("dd/MM/yyyy").format(date)+"_"+DateTimeFormat.getFormat("SSS").format(date));
	}

}
